<?php
/**
 * Created by PhpStorm.
 * User: wxy
 * Date: 2017/9/5
 * Time: 9:50
 */

namespace frontend\modules\common\models;


class BaseParam
{
    //图片前缀
    public static $imgUrl = 'http://local.tdx.com/upload/images/';
    //所有页面page大小
    public static $page = 20;
    //banner状态
    public static $bannerStatus = [1 => '启用', 0 => '禁用',];
    //分馆状态
    public static $branchStatus = [0 => '未开始', 1 => '正常', 2 => '已过期',];
    //分馆显示隐藏
    public static $branchShow = [0 => '隐藏', 1 => '显示',];
    //用户账户状态
    public static $userBranchStatus = [0 => '冻结', 1 => '正常'];
    //资源分类 状态
    public static $cateStatus = [0 => '隐藏', 1 => '显示',];
    //资源分类 添加预设
    public static $cateAddDefault = [0 => '作为一级分类'];
    //资源类型
    public static $resourceType = [1 => '图书', 2 => '期刊', 3 => '图片', 4 => '音频', 5 => '视频',];

    public static $excelSavePath = '../runtime/excel/';
    //
    public static $UserExcelHeader = [
        'A' => 'phone',
        'B' => 'user_name',
        'C' => 'id_number',
    ];
    //图书
    public static $bookExcelHeader = [
        'A' => 'res_code',
        'B' => 'res_title',
        'C' => 'res_subtitle',
        'D' => 'res_volume',
        'E' => 'cat_id2',
        'F' => 'author',
        'G' => 'publisher',
        'H' => 'create_date',
        'I' => 'isbn',
        'J' => 'cl_cat_id',
        'K' => 'keyword',
        'L' => 'summary',
        'M' => 'page_num',
        'N' => 'resource_id',
        'O' => 'url',
        'P' => 'cover_img',
    ];
    //期刊
    public static $periodicalExcelHeader = [
        'A' => 'res_code',
        'B' => 'res_title',
        'C' => 'res_subtitle',
        'D' => 'cat_id2',
        'E' => 'author',
        'F' => 'publisher',
        'G' => 'create_date',
        'H' => 'pub_year',
        'I' => 'pub_month',
        'J' => 'pub_sn',
        'K' => 'issn',
        'L' => 'cn',
        'M' => 'period',
        'N' => 'cl_cat_id',
        'O' => 'keyword',
        'P' => 'summary',
        'Q' => 'postcode',
        'R' => 'pub_address',
        'S' => 'resource_id',
        'T' => 'url',
        'U' => 'cover_img',
    ];
    //图片
    public static $pictureExcelHeader = [
        'A' => 'res_code',
        'B' => 'res_title',
        'C' => 'res_othertitle',
        'D' => 'cat_id2',
        'E' => 'author',
        'F' => 'author_intro',
        'G' => 'create_date',
        'H' => 'create_adress',
        'I' => 'cl_cat_id',
        'J' => 'keyword',
        'K' => 'summary',
        'L' => 'size',
        'M' => 'material',
        'N' => 'resource_id',
        'O' => 'url',
        'p' => 'cover_img',
    ];
    //音频
    public static $audioExcelHeader = [
        'A' => 'res_code',
        'B' => 'res_title',
        'C' => 'res_othertitle',
        'D' => 'cat_id2',
        'E' => 'author',
        'F' => 'author_intro',
        'G' => 'create_date',
        'H' => 'create_adress',
        'I' => 'cl_cat_id',
        'J' => 'keyword',
        'K' => 'summary',
        'L' => 'length',
        'M' => 'album_title',
        'N' => 'album_engtitle',
        'O' => 'resource_id',
        'P' => 'url',
        'Q' => 'cover_img',
    ];
    //视频
    public static $videoExcelHeader = [
        'A' => 'res_code',
        'B' => 'res_title',
        'C' => 'res_othertitle',
        'D' => 'cat_id2',
        'E' => 'author',
        'F' => 'author_intro',
        'G' => 'create_date',
        'H' => 'create_adress',
        'I' => 'organization',
        'J' => 'cl_cat_id',
        'K' => 'keyword',
        'L' => 'summary',
        'M' => 'length',
        'N' => 'resource_id',
        'O' => 'url',
        'P' => 'cover_img',
    ];

    /**
     * @param $date
     * @param $value
     * @return string
     */
    public static function CodeHelper($date, $value)
    {

        if (isset($date[$value])) {
            return $date[$value];
        } else {
            return '未设置';
        }
    }

    //无限极分类
    public static function dealUnlimitedCate($array, $name1 = 'parent_id', $name2 = 'children')
    {

        $items = $array;
        //第二部 遍历数据 生成树状结构
        $tree = array();
        foreach ($items as $key => $value) {
            if (isset($items[$value[$name1]])) {
                $items[$value[$name1]][$name2][] = &$items[$key];
            } else {
                $tree[] = &$items[$key];
            }
        }
        return $tree;
    }

}